package com.third.tencentlogin.config;

import com.third.tencentlogin.oauth.api.QQApi;
import com.third.tencentlogin.oauth.service.OAuthServiceDeractor;
import com.third.tencentlogin.oauth.service.QQOAuthServices;
import org.scribe.builder.ServiceBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OAuthConfig {
    private static final String CALLBACK_URL = "http://localhost:8080/oauth/%s/callback";

    @Value("${oAuth.qq.state}")
    String state;

    @Value("${oAuth.qq.appId}")
    String qqAppid;

    @Value("${oAuth.qq.appKey}")
    String qqAppkey;


    @Bean
    public QQApi githubApi(){
        return new QQApi(state);
    }

    @Bean
    public OAuthServiceDeractor getQQOAuthService(){
        return new QQOAuthServices(new ServiceBuilder()
                .provider(githubApi())
                .apiKey(qqAppid)
                .apiSecret(qqAppkey)
                .callback(String.format(CALLBACK_URL,OAuthTypes.QQ))
                .build());
    }
}
